<%@page import="com.elookinto.wordlist.MobileDeviceDetector"%>
<%@page contentType="text/html" pageEncoding="UTF-8" import="java.io.*, java.sql.*, javax.sql.*, org.brickred.socialauth.*"%>
<%

    response.setHeader("Cache-Control", "no-cache");
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", -1);

    Cookie cookies[] = request.getCookies();
    Cookie myCookie = null;
    String cookieUid = "uid";

    if (cookies != null) {
        for (int i = 0; i < cookies.length; i++) {
            // out.println(cookies[i].getName() + "--- " + cookies[i].getValue() + "<br/>");
            if (cookies[i].getName().equals(cookieUid)) {
                myCookie = cookies[i];
                break;
            }

        }
    }
    String uid = null;
    String loginAccount = null;
    if (session.getAttribute("uid") == null) {
        SocialAuthManager manager = (SocialAuthManager) session.getAttribute("authManager");
        try {
            if (manager != null) {
                java.util.Map<String, String> paramsMap = org.brickred.socialauth.util.SocialAuthUtil.getRequestParametersMap(request);
                AuthProvider provider = manager.connect(paramsMap);
                if (provider != null) {
                    Profile p = provider.getUserProfile();
                    if (p != null && p.getEmail() != null) {
                        uid = p.getEmail();
                    } else {
                        uid = p.getFullName() + p.getDisplayName();
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        loginAccount = uid;
    }

    if (uid != null) {
        session.setAttribute("uid", uid);
    } else {
        if (myCookie != null) {
            uid = myCookie.getValue();
            session.setAttribute("uid", uid);
        } else {
            uid = request.getRemoteHost();
            session.setAttribute("uid", uid);
        }
    }
    //out.println("uid=" + uid);
    Cookie cookie = new Cookie("uid", session.getAttribute("uid").toString());
    cookie.setMaxAge(365 * 24 * 60 * 60);
    response.addCookie(cookie);
    String saveListName = request.getParameter("listName");
    String saveWord = request.getParameter("word");
    String gotoTab = request.getParameter("gotoTab");
    if (gotoTab != null) {
        session.setAttribute("gotoTab", gotoTab);
    }

%>
<!DOCTYPE html>
<html>
    <head>

        <meta name="HandheldFriendly" content="true" />
        <meta name="viewport" content="width=device-width, height=device-height, user-scalable=no" />
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
        <meta name="title" content="Word List" />
        <meta name="description" content=" This word list app is the best tool to help boost your/your family vocabulary. " />
        <meta property="og:title" content="Word List" /> 
        <meta property="og:description" content="This word list app is the best tool to help boost your/your family vocabulary. " /> 
        <title> Word List </title>


        <link rel="stylesheet" type="text/css" media="handheld" href="../css/wordlist.css"/> 
        <link rel="stylesheet" type="text/css" media="handheld" href="../css/button.css"/> 
        <link rel="stylesheet" type="text/css" media="handheld" href="../css/atd.css" />
        <link rel="stylesheet" type="text/css" media="handheld" href="../js/qtip/jquery.qtip.min.css" />
        <link rel="stylesheet" type="text/css" media="handheld" href="../css/handhelder.css"/> 
        <link rel="stylesheet" type="text/css" href="js/jquery.contextMenu.css"/> 
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
        <script src="http://code.jquery.com/ui/1.8.21/jquery-ui.min.js" type="text/javascript"></script>
        <script type="text/javascript" src="../js/jquery.cookie.js"></script>
        <script type="text/javascript" src="../js/jquery.limit.js"></script>
        <script src="../js/jquery.atd.textarea.js"></script>
        <script src="../js/qtip/jquery.qtip.min.js"> </script>
        <script src="../js/jquery.contextMenu.js"> </script>
        <script src="../js/csshttprequest.js"></script>
         <script type="text/javascript">
           $.get("/detect.php", function(data) {
             if (data.indexOf('true')>=0) {
               $('head').append('<meta name="HandheldFriendly" content="true" />');
               $('head').append('<meta name="viewport" content="width=device-width, height=device-height, user-scalable=no" />');
             }

          });
        </script>

        
        <script type="text/javascript" src="../js/wordlist.js"></script>

        <script type="text/javascript">

            var _gaq = _gaq || [];
            _gaq.push(['_setAccount', 'UA-9033082-1']);
            _gaq.push(['_trackPageview']);

            (function() {
                var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
                ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
                var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
            })();

        </script>
        <script type="text/javascript">
            $(document).ready(function() {
                // Match all <A/> links with a title tag and use it as the content (default).
	     
                $('#upload').limit('1000','#charsLeft');
                $('#note').limit('1000','#charsLeft');
                //alert( "cookie" + $.cookie("currentWordList"))
                $.get("retrieve.jsp", {listName: $.cookie("currentWordList"), pub:$.cookie("pub")}, function(data) {
                    // alert(data);
                    $("#wordlist").html(data);
                    $('a.button').qtip();
                });   
                
                
            <% if (saveListName != null && saveWord != null) {%>
                    var saveListName = "<%= saveListName%>";
                    var saveWord = "<%= saveWord%>";
                    //alert(saveWord);
                    //alert(saveListName);
                    $.post("../save.jsp", 
                    {
                        wordList:saveWord, 
                        listName: saveListName }
                    ,
                    function(data2){
                        $.cookie("currentListName", saveListName );
                        retrieveMyList();
                        $("#message").text("Your word '" +saveWord+ "' has been saved to list '"+ saveListName +"'!");

                        var currentWord = saveWord;
                        $.get("../retrieve.jsp", {
                            listName: saveListName,
                            currentWord: saveWord
                        }, function(data4) {
                            // alert(data4);
                            // $("#wordlist").html("damnit");
                             
                            $("#wordlist").html(data4);
                            $('#listname').val("");
                            $('#upload').val("");
                        }); 
                    });
                        
                        
            <% } else {%>
                    retrieveMyList();
            <%}%>
                    $("#listname").focus(function() {
                        var $this = $(this);
                        $this.select();
                        // Work around Chrome's little problem
                        $this.mouseup(function() {
                            // Prevent further mouseup intervention
                            $this.unbind("mouseup");
                            return false;
                        });
                    });
                    //$('a[title]').qtip();
                });
            
           
         
        </script>



    </head>
    <body>
        <div class="wrapper">
            <div id="fb-root"></div>

            <div>
                <div class="topmenu">  <div class="topmenu"> <a href="/wordlist"> Wordlist </a> 
                        <a href="/wordlist_chinese"> ChineseWordlist </a>  
                    </div>
                    <h2 align="center"> Word Lists  
                    </h2>
                    <div style="float:right" class="fb-like" data-href="http://www.elookinto.com/wordlist" data-send="true" data-width="450" data-show-faces="true"></div>
                </div>
                <!--
              <div><object id="test" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" 
                           codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="15" height="15"><PARAM NAME=movie VALUE="http://www.strangecube.com/audioplay/online/audioplay.swf?file=http://onelook.com/pronounce/macmillan/US/word-American-English-pronunciation.mp3&auto=no&sendstop=yes&repeat=1&buttondir=http://www.strangecube.com/audioplay/online/alpha_buttons/negative_small&bgcolor=0xffffff&mode=playpause"><PARAM NAME="allowScriptAccess" value="always" /> <PARAM NAME=quality VALUE=high><PARAM NAME=wmode VALUE=transparent><PARAM NAME=einterface VALUE=yes><embed einterface="yes" allowScriptAccess="always" name="test" 
                                                                                                                                                                                                        src="http://www.strangecube.com/audioplay/online/audioplay.swf?file=http://onelook.com/pronounce/macmillan/US/word-American-English-pronunciation.mp3&auto=no&sendstop=yes&repeat=1&buttondir=http://www.strangecube.com/audioplay/online/alpha_buttons/negative_small&bgcolor=0xffffff&mode=playpause&einterface=yes"
                                                                                                                                                                                                        quality=high wmode=transparent width="15" height="15" align="" TYPE="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object></div>
        
                <button onclick="play1('connection')"> test </button>
                -->



                <div id="gradeList" style="text-align: center;background-color:lightblue;margin-left: 100px;margin-right: 100px"> </div>

                <div width="100%" id="myWordList" style="text-align: center;background:lavenderblush">

                </div>
                <div style="text-align: center">
                    <%
                        if (uid.equals(request.getRemoteHost())) {%>


                    <a href="facebook.jsp" title="facebook"><img  src="http://opensource.brickred.com/socialauthdemo/images/facebook_icon.png" /></a>
                    <a href="yahoo.jsp" title="yahoo"><img  src="http://opensource.brickred.com/socialauthdemo/images/yahoomail_icon.jpg" /></a>
                    <a href="twitter.jsp"  title="twitter"><img src="http://opensource.brickred.com/socialauthdemo/images/twitter_icon.png" /></a>
                        <%-- <a href="google.jsp" title="google"><img src="http://socialauth.in/socialauthdemo/images/gmail-icon.jpg" /></a> --%>

                    <%} else {%>
                    <a href="../logout.jsp"> logout </a>
                    <%}%>
                </div>
                <div id="inputarea" style="display:none;vertical-align:text-top;width:100%" >
                    <table>
                        <tr> <td>
                                Type/Paste Words :<br/> <textarea  id="upload" cols="30" rows="5"> </textarea>
                            </td>

                        </tr>
                    </table>


                    List Name: <input   size="45" maxlength="65" id="listname" type="text" />
                    <img src="images/atdbuttontr.gif"><a href="javascript:check()" id="checkLink">Check Spelling</a>
                </div>

                <button id="b" onclick="upload(this)"> Upload words </button> <button onclick="" > Upload Your Recording URL </button>
                <span style="color:red;" id="message" > </span>
                <br/>


                <div id="wordlist" >

                </div>




                <div class="push"> </div>
            </div>
            <div class="push"> </div>
            <div class='footer' style="width:100%;text-align:center">
                <!--
                <a href="https://chrome.google.com/webstore/detail/demkilcilciablmnmbnnlknjnphcloae"> Install from Chrome Store 2.0 </a> 
                -->


                Copyright (c) 2012, elookinto.  <a style="text-decoration: none" href="https://groups.google.com/forum/?fromgroups#!forum/wordlists" target="support"> Support Forum </a>

            </div>

    </body>
</html>

